package com.wms.entity;


import com.baomidou.mybatisplus.annotation.TableField;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Admin extends BaseEntity implements UserDetails {

    /**
     * 用户名
     */
    @NotNull(message = "用户名不为空")
    private String username;

    /**
     * 密码
     */
    private String password;


    /**
     * 角色
     */
    @TableField(exist = false)
    private Role role;

    /**
     * 权限
     */
    @TableField(exist = false)
    private List<Authority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public String getRoleName(){
        return this.role != null ? this.role.getName() : null;
    }

}
